<template>
	<view class="ys">
		<view class="no-list" v-if="list.length == 0">
			<image src="/static/index/nolist.png" mode="widthFix"></image>
			- 暂无数据 -
		</view>
		<view class="goods">
			<view class="goodsitem" v-for="(item,index) in list" :key='item.id' @click="toPage('./edit?id='+item.id)">
				<image :src="item.cover_path" mode=""></image>
				<text class="name">{{item.name}}</text>
				<view class="price">
					<view>
						￥<text class="pricenum">{{item.price}}</text>
					</view>
					<view class="sell">
						库存:{{item.stock}}
					</view>
				</view>
			</view>
		</view>
		<view class="add" @click="toPage('./add')">
			<image src="/static/index/add2.png" mode=""></image>
		</view>
	</view>
</template>

<script>
	import {
		lst
	} from "@/api/user.js"
	export default {
		data() {
			return {
				list: [],
				page: 1,
				last_page: 1
			}
		},
		onShow() {
			this.page = 1
			this.last_page = 1
			this.list = []
			this.lst()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.lst()
			}
		},
		methods: {
			lst() {
				lst({
					page: this.page
				}).then(res => {
					if (res.code == 0) {
						this.list = this.list.concat(res.data.data)
					} else {
						uni.$showMsg(res.msg, function() {
							uni.navigateBack()
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.add {
		position: fixed;
		z-index: 1005;
		right: 0;
		bottom: 10%;

		image {
			width: 60px;
			height: 60px;
		}
	}

	.goods {
		display: table;
		width: 100%;

		.goodsitem {
			display: flex;
			flex-direction: column;
			width: 45%;
			float: left;
			margin: 20rpx 2.5%;
			background: #fff;
			border-radius: 5px;

			image {
				width: 100%;
				height: 180px;
				border-radius: 5px;
			}

			.name {
				font-size: 15px;
				width: 100%;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				font-weight: bold;
				padding: 5px;
			}

			.des {
				padding: 0 5px;

				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
				overflow: hidden;
				font-size: 12px;
				color: #777;
			}

			.price {
				color: #C79E76;
				font-size: 14px;
				padding: 5px;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.pricenum {
					font-size: 18px;
					font-weight: bold;
				}

				.sell {
					font-size: 12px;
				}
			}

			.vipprice {
				font-size: 14px;
			}
		}
	}
</style>